<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-08-22
 * Time: 16:58
 */

namespace App\Model\Mobile;


use App\Model\Base;
use Illuminate\Support\Facades\DB;

class MobilePlan extends Base
{

    public $mobile_plan;

    public function __construct()
    {
        parent::__construct();
        $this->mobile_plan = 'mobile_plan';//移动端标记表
//        $this->mobile_plan = 'mobile_plan'.'_'.$this->branch_id;//移动端标记表
    }

    //计划任务列表
    public function listPlan()
    {
       // dd($this->uid);
        $hmp_sign_type = DB::table($this->mobile_plan)->where('hmp_user_id', $this->uid)
            ->value(DB::raw('GROUP_CONCAT(hmp_sign_type) as hmp_sign_type'));
        if (!$hmp_sign_type) {
            return false;
        }
        $hmp_sign_type = explode(',', $hmp_sign_type);
        $hmp_sign_type = array_unique($hmp_sign_type);
        $data = [];
        foreach ($hmp_sign_type as $k => $v) {
            $data[$k] = DB::table($this->mobile_plan)->select('*')->where('hmp_sign_type', $v)->get();
        }
        return $data;
    }

    //更改计划任务
    public function updatePlan($params){
        return DB::table($this->mobile_plan)
            ->where('hmp_user_id', $this->uid)
            ->where('hmp_id',$params['hmp_id'])
            ->update([
                'hmp_sign_type'=>$params['hmp_sign_type'],
                'hmp_status'=>$params['hmp_status'],
                'hmp_plan_time'=>$params['hmp_plan_time'],
                'hmp_remarks'=>isset($params['hmp_remarks']) ? $params['hmp_remarks'] : '' ,
                'hmp_update_time'=>time()
             ]);
    }

    //删除计划任务
    public function delPlan($params){
        return DB::table($this->mobile_plan)
            ->where('hmp_sign_type', $params['hmp_sign_type'])
            ->where('hmp_user_id', $this->uid)
            ->delete();
    }
}